package com.wx.mythread.background;


/**
 * 初始化还未完成，就this赋值
 */
public class MultiThreadError4 {
    static Point point;

    public static void main(String[] args) {
        new PointMaker().start();
        try {
            Thread.sleep(10);
            // Thread.sleep(105);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(point);
    }


}

class Point{
    private final int x,y;

    Point(int x, int y) {
        this.x = x;
        MultiThreadError4.point = this;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //因为上面休眠100ms，导致初始化还未完成，就已经赋值出去
        this.y = y;
    }

    @Override
    public String toString() {
        return "Point{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}

class PointMaker extends Thread{
    @Override
    public void run() {
        try {
            new Point(1, 2);
        }catch (Exception e){
            System.out.println(e);
        }

    }
}
